#include "Sentence.h"

ostream& operator<<(ostream& os, const Sentence& s){
	os << s.isFrameExample << "\n" << s.isWithFrame << "\n" << s.words.size() << "\n";

	for( Words::const_iterator word = s.words.begin(); word != s.words.end(); word++ ){
		os << word->isFrequent << "\t" << (word->isFilter ? 1 : 0) << "\t";
		os << word->name << "\t" << word->role << "\t" << word->connector << "\t";
		os << word->semanticClass << "\t" << word->semanticSubClass << "\t";
		os << word->clauseType << "\t" << word->taxisInfo << "\t";
		os << word->grammaticalCase << "\t" << word->original << "\t";
		os << word->partOfSentence << "\t" << word->speechPart.size() << "\t";

		for ( vector<string>::const_iterator j = word->speechPart.begin(); j != word->speechPart.end(); j++ ){
			os << *j << "\t";
		}
	}

	os << "\n" << s.wordsVector.size() << "\n";
	for(StringIntMap::const_iterator word = s.wordsVector.begin(); word != s.wordsVector.end(); word++){
		os << word->first << ";" << word->second << ";";
	}

	os << "\n" << s.wordsCleanVector.size() << "\n";
	for(StringIntMap::const_iterator word = s.wordsCleanVector.begin(); word != s.wordsCleanVector.end(); word++){
		os << word->first << ";" << word->second << ";";
	}

	os << "\n" << s.wordsRoleVector.size() << "\n";
	for(StringIntMap::const_iterator word = s.wordsRoleVector.begin(); word != s.wordsRoleVector.end(); word++){
		os << word->first << ";" << word->second << ";";
	}

	os << "\n" << s.wordsRoleCleanVector.size() << "\n";
	for(StringIntMap::const_iterator word = s.wordsRoleCleanVector.begin(); word != s.wordsRoleCleanVector.end(); word++){
		os << word->first << ";" << word->second << ";";
	}

	os << "\n" << s.features.size() << "\n";
	for( unsigned int j = 0; j < s.features.size(); j++){
		os << s.features[j] << "\t";
	}

	os << "\n";

	return os;
}

istream& operator>>(istream& from, Sentence& s){
	unsigned int count;
	char c;

	from >> s.isFrameExample >> s.isWithFrame >> count;

	for( unsigned int j = 0; j < count; j++){
		s.words.push_back(Word());
		Words::reverse_iterator newWord = s.words.rbegin();

		unsigned int length;
		if( j == 0 )
			from.get(c);

		from >> newWord->isFrequent;
		//from >> newWord->isFilter;
		from.get(c);

		newWord->name = getLine(from, '\t');
		newWord->role = getLine(from, '\t');
		newWord->connector = getLine(from, '\t');
		newWord->semanticClass = getLine(from, '\t');
		newWord->semanticSubClass = getLine(from, '\t'); 
		newWord->clauseType = getLine(from, '\t');
		newWord->taxisInfo = getLine(from, '\t');
		newWord->grammaticalCase = getLine(from, '\t');
		newWord->original = getLine(from, '\t');
		newWord->partOfSentence = getLine(from, '\t');

		from >> length;
		from.get(c);

		for( unsigned int z = 0; z < length; z++){
			newWord->speechPart.push_back(getLine(from, '\t'));
		}
	}

	if( count > 0 )
		from.get(c);

	from >> count;

	for( unsigned int j = 0; j < count; j++){
		string word;
		int v;
		from.get(c);
		word = getLine(from, ';');
		from >> v;
		s.wordsVector.insert(StringIntMap::value_type(word, v));
	}
	if( count > 0 )
		from.get(c);

	from >> count;

	for( unsigned int j = 0; j < count; j++){
		string word;
		int v;
		from.get(c);
		word = getLine(from, ';');
		from >> v;
		s.wordsCleanVector.insert(StringIntMap::value_type(word, v));
	}
	if( count > 0 )
		from.get(c);

	from >> count;

	for( unsigned int j = 0; j < count; j++){
		string word;
		int v;
		from.get(c);
		word = getLine(from, ';');
		from >> v;
		s.wordsRoleVector.insert(StringIntMap::value_type(word, v));
	}
	if( count > 0 )
		from.get(c);

	from >> count;

	for( unsigned int j = 0; j < count; j++){
		string word;
		int v;
		from.get(c);
		word = getLine(from, ';');
		from >> v;
		s.wordsRoleCleanVector.insert(StringIntMap::value_type(word, v));
	}
	if( count > 0 )
		from.get(c);

	from >> count;

	for( unsigned int z = 0; z < count; z++){
		double v;
		from >> v;
		s.features.push_back(v);
	}

	from.get(c);

	return from;
}